package com.dao.impl;

import java.util.List;

public class CustomerDao {
	import java.util.List;

import com.pos43.domain.User;

import dao.ICustomerDao;

	public class CustomerDao extends HibernateDaoSupport implements ICustomerDao{
			
			public Customer get(Integer id){
				return getHibernateTemplate().get(Customer.class, id);
			}
			
			public Integer save(Customer customer){
				return (Integer)getHibernateTemplate()
					.save(customer);
			}
			
			public void update(Customer customer){
				getHibernateTemplate().update(customer);
			}
			
			public void delete(Customer customer){
				getHibernateTemplate().delete(customer);
			}
			
			public void delete(Integer id){
				getHibernateTemplate().delete(get(id));
			}
			
			public List<Customer> findAll(){
				return (List<Customer>)getHibernateTemplate()
						.find("from Customer");
			}
			@Override
			public List<Customer> findByParam(String key) {
				String hql = "from Customer c where c.name like '%" + key + "%'";
				return this.getSession()
						.createQuery(hql)
						.list();
			}

			@Override
			public List<Customer> get(Customer customer) {
				return this.getSession()
						.createQuery("from Customer c where c.id=? and c.pwd=?")
						.setParameter(0, user.getId())
						.setParameter(1, user.getPwd())
						.list();
			}

		}